<template>
  <el-dialog v-model="dialogVisible" title="审核" width="500" :before-close="handleClose">
    <el-form :model="formInline" label-width="50">
      <el-form-item label="审核">
        <el-radio-group v-model="formInline.status">
          <el-radio :label="1">通过</el-radio>
          <el-radio :label="0">不通过</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="formInline.requirement" placeholder="请输入备注" type="textarea" :autosize="{ minRows : 4 }" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="save" :loading="loading">
          确 认
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
const { proxy } = getCurrentInstance();
let props = defineProps(["request"]);
const emit = defineEmits(["fatherMethods"]);

let dialogVisible = ref(false);
let loading = ref(false);
let formInline = ref({
  status: 1,
  jobPostId: "",
  requirement: "",
});

let open = (id) => {
  formInline.value.jobPostId = id;
  dialogVisible.value = true;
};
let handleClose = () => {
  formInline.value = {
    status: 1,
    jobPostId: "",
    requirement: "",
  };
  emit("fatherMethods");
  dialogVisible.value = false;
};
let save = async () => {
  try {
    loading.value = true;
    let sameParams = [
      "finishCompanyControllerAudit",
      "workDiaryAudit",
      "workCaseEvaluateAudit",
      "companyDiaryControllerAudit",
    ];
    let params = {};
    if (sameParams.includes(props.request)) {
      params = {
        auditContent: formInline.value.requirement,
        auditState: formInline.value.status == 1 ? "02" : "03",
        id: formInline.value.jobPostId,
      };
    }
    switch (props.request) {
      case "jobPostAudit": //招工管理
        await proxy.$apis.jobPostAudit(formInline.value);
        break;
      case "workCaseAudit": //工人案例
        let query = {
          workId: formInline.value.jobPostId,
          auditContent: formInline.value.requirement,
          auditState: formInline.value.status == 1 ? "02" : "03",
        };
        await proxy.$apis.workCaseAudit(query);
        break;
      case "finishCompanyControllerAudit": //装修公司
        await proxy.$apis.finishCompanyControllerAudit(params);
        break;
      case "workDiaryAudit": //个人案例日记
        await proxy.$apis.workDiaryAudit(params);
        break;
      case "workCaseEvaluateAudit": //个人案例评论
        await proxy.$apis.workCaseEvaluateAudit(params);
        break;
      case "companyDiaryControllerAudit": //装修公司日志
        await proxy.$apis.companyDiaryControllerAudit(params);
        break;
      default:
        break;
    }
    proxy.$utils.showToast("审批成功");
    handleClose();
  } catch (error) {
  } finally {
    loading.value = false;
  }
};

defineExpose({ open });
</script>

<style lang="scss" scoped>
</style>
